package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckGroupService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/checkGroup")
public class CheckGroupController {
    @Reference(version = "1.0.0")
    private CheckGroupService checkGroupService;

    @PostMapping("/findPage")
    public Result findPage(@RequestBody QueryPageBean queryPageBean) {
        if(queryPageBean.getQueryString()!=null&&queryPageBean.getCurrentPage()!=1){
            queryPageBean.setCurrentPage(1);
        }
        return checkGroupService.findPAge(queryPageBean);
    }


    @PostMapping("/findAll")
    public Result findAll() {
         List<CheckItem> checkItemList = checkGroupService.findAll();
         return Result.success(checkItemList);
    }

    @PostMapping("/add")
    public Result add(@RequestBody CheckGroup checkGroup) {
        return checkGroupService.add(checkGroup);
    }



   @GetMapping("/findById")
    public Result findById(Integer id) {
        return checkGroupService.findById(id);
    }


    @PostMapping("/update")
    public Result update(@RequestBody CheckGroup checkGroup) {
        return checkGroupService.update(checkGroup);
    }

    @GetMapping("/delete")
    public Result delete(Integer id) {
        return checkGroupService.delete(id);
    }



}
